/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.web.suggest;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unis.common.ui.jqGrid.GridUIMapper;
import com.unis.common.util.WebUtil;
import com.unis.model.BaseModel;
import com.unis.model.suggest.Suggest;
import com.unis.service.suggest.SuggestService;

/**
 * @author Administrator (email:granzy@sohu.com)
 * @since 2013-02-25
 */
@Controller
@RequestMapping("/suggest")
public class SuggestController {

    private SuggestService suggestService;

    /****************************************
     * Insert a instace of Suggest
     ****************************************/
    @RequestMapping("/insert")
    @ResponseBody
    public Object insertSuggest(@RequestBody Suggest suggest) throws Exception {
        suggest.setStatmentId("Suggest.insert");
        String status = "failure";
        suggestService.insert(suggest);
        status = "success";
        return status;
    }

    /****************************************
     * Update a instace of Suggest
     ****************************************/
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody Suggest suggest) throws Exception {
        suggest.setStatmentId("Suggest.update");
        String status = "failure";
        suggestService.update(suggest);
        status = "success";
        return status;
    }

    /****************************************
     * Delete a instace of Suggest
     ****************************************/
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody Suggest suggest) throws Exception {
        suggest.setStatmentId("Suggest.delete");
        String status = "failure";
        suggestService.batchDelete(suggest);
        status = "success";
        return status;
    }

    /****************************************
     * Query instaces of Suggest
     ****************************************/
    @RequestMapping("/queryAsList")
    @ResponseBody
    public Object queryAsList(HttpServletRequest request) throws Exception {
        Map<String, Object> paramMap = WebUtil.getParamsMapFromRequest(request);
        Suggest suggest = new Suggest();
        suggest.setStatmentId("Suggest.queryAsList");
        BeanUtils.populate(suggest, paramMap);
        Map<String, Object> pageMap = GridUIMapper.process(paramMap);
        BeanUtils.populate(suggest, pageMap);
        List<BaseModel> suggestList = suggestService.queryAsList(suggest);
        Map<String, Object> renderMap = GridUIMapper.render(suggest, suggestList);
        return renderMap;
    }

    /****************************************
     * Query a instaces of Suggest
     ****************************************/
    @RequestMapping("/queryAsObject")
    @ResponseBody
    public BaseModel queryAsObject(@RequestBody Suggest suggest) throws Exception {
        suggest.setStatmentId("Suggest.queryAsObject");
        return suggestService.queryAsObject(suggest);
    }

    @RequestMapping("/page")
    public String forword() {
        return "suggest/suggestList";
    }

    @Resource
    public void setSuggestService(SuggestService suggestService) {
        this.suggestService = suggestService;
    }
}
